<?php
namespace app\api\controller;

use app\common\controller\Api;

/**
 * 钱包模块
 * User: LK
 * Date: 2021/4/6
 */
class Wallet extends Api
{
    protected $noNeedLogin = ['notify'];
    protected $noNeedRight = '*';

    /**
     * 资金流水
     *
     * @ApiMethod   (POST)
     *
     * @param string $mold 类型:all=全部,earning=收入,expend=支出
     * @param string $start_time 开始时间
     * @param string $end_time 结束时间
     * @param int $page 页码
     * @param int $limit 每页数据
     */
    public function getMoneyLogPageList(\app\common\model\UserMoneyLogModel $UserMoneyLogModel, \app\api\validate\WalletValidate $WalletValidate)
    {
        $params = $this->request->post();
        if(!$WalletValidate->check($params,[],'getMoneyLogPageList')){
            $this->errorReturn(40001,$params,$WalletValidate->getError());
        }
        $user_id = $this->auth->id;
        $page = $this->request->request('page');
        $limit = $this->request->request('limit');
        $return = $UserMoneyLogModel->getMoneyLogPageList($params,$user_id,$page,$limit);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }


    /**
     * 充值
     *
     * @ApiMethod   (POST)
     *
     * @param string $platform 平台:pc=PC,mini=小程序,app=App
     * @param string $pay_type 支付类型:alipay=支付宝,wxpay=微信
     * @param string $money 充值金额
     */
    public function rechargeMoney(\app\common\model\UserRechargeLogModel $UserRechargeLogModel, \app\api\validate\WalletValidate $WalletValidate)
    {
        $params = $this->request->post();
        if(!$WalletValidate->check($params,[],'rechargeMoney')){
            $this->errorReturn(40001,$params,$WalletValidate->getError());
        }
        $user_id = $this->auth->id;
        $params['openid'] = $this->auth->openid;
        $return = $UserRechargeLogModel->rechargeMoney($params, $user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

    /**
     * 支付下单回调处理
     */
    public function notify(\app\common\model\UserRechargeLogModel $UserRechargeLogModel)
    {
        $type = $this->request->param('paytype');
        $method = $this->request->param('method');
        $UserRechargeLogModel->notify($type,$method);
    }

    /**
     * 积分记录分页列表
     *
     * @ApiMethod   (POST)
     *
     * @param string $mold 类型:all=全部,earning=收入,expend=支出
     * @param string $start_time 开始时间
     * @param string $end_time 结束时间
     * @param int $page 页码
     * @param int $limit 每页数据
     */
    public function getScoreLogPageList(\app\common\model\ScoreLog $ScoreLog, \app\api\validate\WalletValidate $WalletValidate)
    {
        $params = $this->request->post();
        if(!$WalletValidate->check($params,[],'getScoreLogPageList')){
            $this->errorReturn(40001,$params,$WalletValidate->getError());
        }
        $user_id = $this->auth->id;
        $page = $this->request->request('page');
        $limit = $this->request->request('limit');
        $return = $ScoreLog->getPageList($params,$user_id,$page,$limit);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

    /**
     * 佣金记录分页列表
     *
     * @ApiMethod   (POST)
     *
     * @param string $start_time 开始时间
     * @param string $end_time 结束时间
     * @param int $page 页码
     * @param int $limit 每页数据
     */
    public function getBrokerageLogPageList(\app\common\model\UserBrokerageLogModel $UserBrokerageLogModel, \app\api\validate\WalletValidate $WalletValidate)
    {
        $params = $this->request->post();
        if(!$WalletValidate->check($params,[],'getBrokerageLogPageList')){
            $this->errorReturn(40001,$params,$WalletValidate->getError());
        }
        $user_id = $this->auth->id;
        $page = $this->request->request('page');
        $limit = $this->request->request('limit');
        $return = $UserBrokerageLogModel->getPageList($params,$user_id,$page,$limit);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

}